package com.micro.plugins.jwt.load;

import com.micro.plugins.jwt.bean.MicroJwt;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;

import javax.annotation.PostConstruct;

/**
 * <h1>jwt配置文件</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020/5/9
 */
@Slf4j
@Data
@Component
public class JwtLoadConfiguration {

    private static final String PROFILE_PATH_JWT_YAML = "jwt.yaml";

    /**
     * jwt参数配置
     */
    private MicroJwt microJwt;


    /**
     *  用户公钥
     */
    private byte[] userPubKey;

    /**
     * 用户私钥
     */
    private byte[] userPriKey;

    /**
     * <h2>初始化jwt文件信息</h2>
     */
    @PostConstruct
    public void initJwt(){
        log.info("****** 初始化jwt配置文件开始 ******");
        Yaml yaml = new Yaml();
        this.microJwt = yaml.loadAs(this.getClass().getClassLoader().getResourceAsStream(PROFILE_PATH_JWT_YAML), MicroJwt.class);
        log.info("****** 初始化jwt配置文件结束 ******");
    }
}
